#include "openssl/evp.h" // add openssl/evp to support sha256
#include <chrono>
#include <iostream>
#include <vector>

using namespace std;

#define SHA256_DIGEST_LENGTH 32

void calc_hash_of_data_with_sha256(const char* data, uint64_t length, std::string& res_hash)
{
    unsigned len = length;
    unsigned char hash[SHA256_DIGEST_LENGTH];
    EVP_MD_CTX* evpCtx = EVP_MD_CTX_new();
    EVP_DigestInit_ex(evpCtx, EVP_sha256(), NULL);
    EVP_DigestUpdate(evpCtx, data, length);
    EVP_DigestFinal_ex(evpCtx, hash, &len);
    for (size_t i = 0; i < SHA256_DIGEST_LENGTH; i++)
        res_hash += hash[i];
}

const uint64_t dataLen = (uint64_t)1024 * 1024 * 1024 * 2;
const int roundNum = 1;

int main()
{
    string s;
    s.resize(dataLen);
    string res_hash;
    auto pos1 = chrono::steady_clock::now();
    for (int i = 0; i < roundNum; i++) {
        calc_hash_of_data_with_sha256(s.c_str(), s.length(), res_hash);
    }
    auto pos2 = chrono::steady_clock::now();
    chrono::duration<double, milli> dur1 = pos2 - pos1;
    cout << dur1.count() << endl;
}
